package com.steam.xbcc.service.impl;

import com.steam.xbcc.domain.Blacklist;
import com.steam.xbcc.domain.MessageSms;
import com.steam.xbcc.enums.GlobalExceptionCode;
import com.steam.xbcc.mapper.MessageSmsMapper;
import com.steam.xbcc.service.IBlacklistService;
import com.steam.xbcc.service.IMessageSmsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.steam.xbcc.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wt
 * @since 2022-09-24
 */
@Service
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {

    @Autowired
    private MessageSmsMapper messageSmsMapper;
    @Autowired
    private IBlacklistService blacklistService;

    @Override
    public void blacklist(Blacklist blacklist) {
        Blacklist black = blacklistService.selectByPhone(blacklist.getPhone());
        AssertUtil.isNull(black, GlobalExceptionCode.PHONE_IS_NOT_NULL);
        //TODO 只能拉黑注册的手机号
        MessageSms messageSms = messageSmsMapper.selectByPhone(blacklist.getPhone());
        Blacklist blacklist1 = new Blacklist();
        blacklist1.setCause(blacklist.getCause());
        blacklist1.setPhone(blacklist.getPhone());
        blacklist1.setBlacklistTime(new Date());
        blacklist1.setIp(messageSms.getIp());
        blacklist1.setUserId(messageSms.getUserId());
        blacklistService.insert(blacklist1);
    }
}
